package netzwerk;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.util.concurrent.CopyOnWriteArrayList;

import model.Order;
import controller.ControllerCustomer;
import fpt.com.Product;

public class IncomingCustomer extends Thread {

	ObjectInputStream in;

	ControllerCustomer controller;

	CopyOnWriteArrayList<Order> ordersFromServer;

	public IncomingCustomer() {
		
	}
	
		
	public IncomingCustomer(ObjectInputStream in, ControllerCustomer controller) {
		this.in = in;
		this.controller = controller;
	}

	@Override
	public void run() {

		while (true) {
			try {
				if (in.readBoolean()) {
					System.out.println("Bestellbestätigung eingetroffen:");
					Order o = new Order();
					try {
						o = (Order) in.readObject();
						System.out.print("Die folgenden Produkte werden Ihnen in Kürze zugestellt: ");
						for(Product p : o){
							System.out.print(p.getName() + "  ");
						}
						System.out.println();
						
					}
					catch (ClassNotFoundException | IOException e) {
						e.printStackTrace();
					}
					controller.guiUpdate(o);
				}
			}
			catch (IOException e) {
				e.printStackTrace();
			}

		}
	}

}
